package com.dmxh.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.fastjson.JSONObject;
import com.dmxh.api.SellerAPI;
import com.dmxh.result.Result;
import com.dmxh.result.ResultConstant;
import com.dmxh.service.SeckillGoodsService;
import com.dmxh.service.SeckillOrderService;
import com.dmxh.util.JwtUtil;
import com.dmxh.vo.UserVO;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@RestController
@RequestMapping("/secKillOrder")
public class SeckillOrderController {

    @Autowired
    private SeckillOrderService seckillOrderService;


    /*抢购  通过界面商品id   生成秒杀订单*/
    @PostMapping("/rush")
    public Result rush(@RequestHeader String frontToken,Long goodsId){
        //获取当前登录用户信息  放进UserVo
        Claims claims = JwtUtil.parseJwt(frontToken);
        String subject = claims.getSubject();
        UserVO userVO = JSONObject.parseObject(subject, UserVO.class);
        return Result.ok().setData(seckillOrderService.rush(userVO,goodsId));
    }
}
